package com.jerry.lastgomall.seckill.controller;

import com.jerry.common.utils.R;
import com.jerry.lastgomall.seckill.service.SeckillScheduledService;
import com.jerry.lastgomall.seckill.to.SeckillSkuRedisTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("seckill/redisSeckill")
public class SeckillController {

    @Autowired
    private SeckillScheduledService seckillSessionService;

    /**
     * 秒杀商品
     */
    @GetMapping("/kill")
    public R secKill(@RequestParam("killId")String killId,
                     @RequestParam("key")String key,
                     @RequestParam("num") Integer num,
                     @RequestParam("userId") Long userId){
        String orderSn=seckillSessionService.secKill(killId,key,num,userId);
        return R.ok().setData(orderSn);
    }

    /**
     * 商品详细信息
     * @param skuId
     * @return
     */
    @GetMapping("/sku/seckill/{skuId}")
    public R getSkuillInfo(@PathVariable("skuId")Long skuId){
        SeckillSkuRedisTO to=seckillSessionService.getSkuillInfo(skuId);
        return R.ok().setData(to);
    }

    /**
     * 返回当前时间可以参与的秒杀商品信息
     * @return
     */
    @GetMapping("/currentSeckillSkus")
    public R getCurrentSeckillSkus(){
        List<SeckillSkuRedisTO> redisTOS=seckillSessionService.getCurrentSeckillSkus();
        return R.ok().setData(redisTOS);
    }
}
